﻿using System;
using System.Data;
using System.Collections.Generic;
using NetDiskPRJ.Common;
using NetDiskPRJ.Model;
namespace NetDiskPRJ.BLL
{
	/// <summary>
	/// 权限用户隶属用户组
	/// </summary>
	public partial class PrvUserGroup
	{
		
		public PrvUserGroup()
		{}
        /// <summary>
        /// 根据用户ID获取用户组ID列表
        /// <creator>wangl</creator>
        /// <date>2013-02-17</date>
        /// </summary>
        /// <param name="logID"></param>
        /// <returns></returns>
        public List<Model.PrvUserGroup> GetGrpListByLogid(string logID)
        {
            NetDiskPRJ.DAL.PrvUserGroup prvUserGroupDAL= new NetDiskPRJ.DAL.PrvUserGroup();
            DataSet ds = prvUserGroupDAL.GetGrpListByLogid(logID);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.PrvUserGroup> GetModelList(string strWhere)
        {
            NetDiskPRJ.DAL.PrvUserGroup prvUserGroupDAL = new NetDiskPRJ.DAL.PrvUserGroup();
            DataSet ds = prvUserGroupDAL.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
         /// <summary>
        /// 删除用户组并删除该用户组下的用户权限
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        public bool DeleteGrpById(string groupNo)
        {
            NetDiskPRJ.DAL.PrvUserGroup prvUserGroupDAL = new NetDiskPRJ.DAL.PrvUserGroup();
            return prvUserGroupDAL.DeleteGrpById(groupNo);
        }
        /// <summary>
        /// 添加用户组成员
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddGrpUser(Model.PrvUserGroup model)
        {
            NetDiskPRJ.DAL.PrvUserGroup prvUserGroupDAL = new NetDiskPRJ.DAL.PrvUserGroup();
            return prvUserGroupDAL.Add(model);
        }
        /// <summary>
        /// 删除用户组成员
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        /// <param name="grp_id"></param>
        /// <returns></returns>
        public bool DeleteGrpUser(Model.PrvUserGroup model)
        {
            NetDiskPRJ.DAL.PrvUserGroup prvUserGroupDAL = new NetDiskPRJ.DAL.PrvUserGroup();
            return prvUserGroupDAL.Delete(model.FLogID,model.FGroupNo);
        }
        /// <summary>
        /// 获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-02-17</date>
        /// </summary>
        private List<NetDiskPRJ.Model.PrvUserGroup> DataTableToList(DataTable dt)
        {
            NetDiskPRJ.DAL.PrvUserGroup prvUserGroupDAL = new NetDiskPRJ.DAL.PrvUserGroup();
            List<NetDiskPRJ.Model.PrvUserGroup> modelList = new List<NetDiskPRJ.Model.PrvUserGroup>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                NetDiskPRJ.Model.PrvUserGroup model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = prvUserGroupDAL.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }
	}
}

